//
//  KLCollectionGoodTableViewCell.m
//  KunLun
//
//  Created by Mac on 2017/11/28.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLShopCarHotleCell.h"
#import "STAutoAddView.h"
@interface BLShopCarHotleCell()
@property(nonatomic, strong) UIImageView                     *iconImageView;
@property(nonatomic, strong) STLabel                     *titleLable;
@property(nonatomic, strong) STLabel                     *guigeLable;
@property(nonatomic, strong) STLabel                     *menberPriceLable;//会员价
@property(nonatomic, strong) STLabel                     *pointPriceLable;//积分价格
@property(nonatomic, strong) STLabel                     *numLable;



@end
@implementation BLShopCarHotleCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    return 135;
}
#pragma mark --subView
- (void)configSubView{
    
    self.chosedButton = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 44, 44)
                                                  title:nil
                                             titleColor:nil
                                              titleFont:0
                                           cornerRadius:0
                                        backgroundColor:nil
                                        backgroundImage:nil
                                                  image:[UIImage imageNamed:@"购物未选中"]];
    
    [self.chosedButton setImage:[UIImage imageNamed:@"购物选中"] forState:UIControlStateSelected];
    self.chosedButton.centerY = [BLShopCarRootTableViewCell cellHeight]/2;
    [self addSubview:self.chosedButton];
    
    
    self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.chosedButton.right , 10, 80, 100)];
    self.iconImageView.image = [UIImage imageNamed:@"个人头像"];
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImageView.clipsToBounds = YES;
    [self addSubview:self.iconImageView];
    
    self.titleLable = [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 5, self.iconImageView.top - 3 , UIScreenWidth - 20 - self.iconImageView.right, 32)
                                                text:@"床单"
                                           textColor:KL_secendTextColor
                                                font:13
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    self.titleLable.numberOfLines = 0;
    [self addSubview:self.titleLable];
    CGFloat maxWith = UIScreenWidth - 15 - self.iconImageView.right - 5;
    STLabel * guigeLable = [[STLabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.titleLable.bottom  +5 , maxWith, 18)
                                                     text:@"制定尺寸:25cm*1.00cm"
                                                textColor:KL_secendTextColor
                                                     font:12
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:guigeLable];
    self.guigeLable = guigeLable;
    
    self.menberPriceLable = [[STLabel alloc] initWithFrame:CGRectMake(guigeLable.left , self.guigeLable.bottom+5 , maxWith, 18)
                                                      text:@"会员价格:185 赠送 46盖币"
                                                 textColor:KL_redColor
                                                      font:12
                                               isSizetoFit:NO
                                             textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.menberPriceLable];
    
    self.pointPriceLable = [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 5, self.menberPriceLable.bottom + 3, maxWith , 18)
                                                     text:@"积分价格：154 + 46积分"
                                                textColor:KL_secendTextColor
                                                     font:12
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.pointPriceLable];
    
    STLabel * numLable = [[STLabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.pointPriceLable.bottom , 35, 18)
                                                   text:@"数量:"
                                              textColor:KL_secendTextColor
                                                   font:12                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentLeft];
    [self addSubview:numLable];
    self.numLable = numLable;
    self.addView = [[STAutoAddView alloc] initWithFrame:CGRectMake(numLable.right + 5, self.pointPriceLable.bottom, 75, 25)];
    self.addView.titleLable.text = @"1";
    [self addSubview:self.addView];
    
    
    
}
- (void)setModel:(BLShopCarModel *)model{
    [super setModel:model];
    NSDictionary * dic = model.goods.firstObject;
    if ([dic.allKeys containsObject:@"img_url"]) {
        NSString * url = dic[@"img_url"];
        NSArray * urls = [url componentsSeparatedByString:@","];
        
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:urls.firstObject]];
    }
    self.titleLable.text = model.name;
    if ([model.type isEqualToString:@"2"] ) {
        //布草酒店定制
        NSString * chang = [NSString stringWithFormat:@"制定尺寸:%@cm*%@cm",model.leng,model.width];
        self.guigeLable.text = chang;
        
        self.menberPriceLable.text = [NSString stringWithFormat:@"会员价:%@  购买将赠送%@盖币",
                                      model.price,
                                      model.grade];
        self.pointPriceLable.text = [NSString stringWithFormat:@"积分价格:￥%@ + %@积分",
                                     model.score_money,
                                     model.make_score];
        
    }
    
    self.addView.titleLable.text = model.num;
    
    self.chosedButton.selected = model.isSlected;
    
}
- (void)setOrderModel:(BLOrderModel *)orderModel{
    [super setOrderModel:orderModel];
    BLGoodModel * model = orderModel.goods[orderModel.indexPath.row];

    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_img_url]];
    self.titleLable.text = model.goods_name;
    
    NSString * chang = [NSString stringWithFormat:@"制定尺寸:%@cm*%@cm",model.length,model.width];
    self.guigeLable.text = chang;
    self.menberPriceLable.text = [NSString stringWithFormat:@"质量标准:%@",model.mass_name];
    self.menberPriceLable.textColor = BL_secendTextColor;
    NSString * huiyuan = [NSString stringWithFormat:@"会员价:￥%@  购买将赠送%@盖币",
                                  model.money,
                                  model.grade];
    NSString * jifen = [NSString stringWithFormat:@"积分价格:￥%@ + %@积分",
                                 model.money,
                                 model.score];
    if (model.score.integerValue > 0) {
        
        self.pointPriceLable.text = jifen;
        
    }else{
        
        self.pointPriceLable.text = huiyuan;
    }
    
    
}
- (void)updateConfimUi{
    
    self.chosedButton.hidden = YES;
    self.iconImageView.left = 15;
    
    self.titleLable.left = self.iconImageView.right + 5;
    self.guigeLable.left = self.iconImageView.right + 5;
    self.menberPriceLable.left = self.iconImageView.right + 5;
    self.pointPriceLable.left = self.iconImageView.right + 5;
    self.numLable.left = self.iconImageView.right + 5;
    
    self.addView.hidden = YES;
    
    self.numLable.width = 200;
    if (self.model) {
         self.numLable.text = [NSString stringWithFormat:@"数量 %@",self.model.num];
    }
    if (self.orderModel) {
         BLGoodModel * model = self.orderModel.goods[self.orderModel.indexPath.row];
        self.numLable.text = [NSString stringWithFormat:@"数量 %@",model.num];
    }
}

@end



